<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\PackageEaseTransfer;

/**
 * PackageEaseTransferSearch represents the model behind the search form about `backend\models\PackageEaseTransfer`.
 */
class PackageEaseTransferSearch extends PackageEaseTransfer
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'package_id', 'method', 'transfer'], 'integer'],
            [['wish', 'detail', 'transfer_title', 'contact', 'phone', 'email', 'address', 'position', 'remark', 'created_at'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = PackageEaseTransfer::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'package_id' => $this->package_id,
            'method' => $this->method,
            'transfer' => $this->transfer,
            'created_at' => $this->created_at,
        ]);

        $query->andFilterWhere(['like', 'wish', $this->wish])
            ->andFilterWhere(['like', 'detail', $this->detail])
            ->andFilterWhere(['like', 'transfer_title', $this->transfer_title])
            ->andFilterWhere(['like', 'contact', $this->contact])
            ->andFilterWhere(['like', 'phone', $this->phone])
            ->andFilterWhere(['like', 'email', $this->email])
            ->andFilterWhere(['like', 'address', $this->address])
            ->andFilterWhere(['like', 'position', $this->position])
            ->andFilterWhere(['like', 'remark', $this->remark]);

        return $dataProvider;
    }
}
